package com.ruoyi.web.controller.map;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.map.domain.VillageInfor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.map.domain.RegionInfo;
import com.ruoyi.map.service.IRegionInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保障房建筑区域信息数据Controller
 *
 * @author dihang
 * @date 2023-07-25
 */
@Api(value = "保障房地图区域数据信息",tags = {"保障房地图区域数据信息"})
@RestController
@RequestMapping("/map/infos")
public class RegionInfoController extends BaseController
{
    @Autowired
    private IRegionInfoService regionInfoService;

    /**
     * 分页条件查询保障房建筑区域信息数据列表
     */
    @ApiOperation(value = "分页条件查询保障房建筑区域信息数据列表")
//    @PreAuthorize("@ss.hasPermi('map:infor:list')")
    @GetMapping("/list/page")
    public IPage<RegionInfo> listPages(RegionInfo regionInfo)
    {
        IPage<RegionInfo> page = regionInfoService.regionSearch(regionInfo);
        return page;
    }

    /**
     * 查询保障房建筑区域信息数据列表
     */
    @ApiOperation(value = "查询保障房建筑区域信息数据列表")
//    @PreAuthorize("@ss.hasPermi('map:info:list')")
    @GetMapping("/list")
    public AjaxResult list()
    {
        List<RegionInfo> list = regionInfoService.selectRegionInfoList();
        return AjaxResult.success(list);
    }

    /**
     * 导出保障房建筑区域信息数据列表
     */
//    @ApiOperation(value = "导出保障房建筑区域信息数据列表")
    @PreAuthorize("@ss.hasPermi('map:info:export')")
    @Log(title = "保障房建筑区域信息数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response)
    {
        List<RegionInfo> list = regionInfoService.selectRegionInfoList();
        ExcelUtil<RegionInfo> util = new ExcelUtil<RegionInfo>(RegionInfo.class);
        util.exportExcel(response, list, "保障房建筑区域信息数据数据");
    }

    /**
     * 获取保障房建筑区域信息数据详细信息
     */
    @ApiOperation(value = "获取保障房建筑区域信息数据详细信息")
    @PreAuthorize("@ss.hasPermi('map:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        RegionInfo regionInfo = regionInfoService.selectById(id);
        return AjaxResult.success(regionInfo);
    }

    /**
     * 新增保障房建筑区域信息数据
     */
    @ApiOperation(value = "新增保障房建筑区域信息数据")
    @PreAuthorize("@ss.hasPermi('map:info:add')")
    @Log(title = "保障房建筑区域信息数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegionInfo regionInfo) {
        regionInfoService.addNew(regionInfo);
        return AjaxResult.success("新增成功");
    }

    /**
     * 修改保障房建筑区域信息数据
     */
    @ApiOperation(value = "修改保障房建筑区域信息数据")
    @PreAuthorize("@ss.hasPermi('map:info:edit')")
    @Log(title = "保障房建筑区域信息数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegionInfo regionInfo) {
        return toAjax(regionInfoService.updateById(regionInfo));
    }

    /**
     * 删除保障房建筑区域信息数据
     */
    @ApiOperation(value = "删除保障房建筑区域信息数据")
    @PreAuthorize("@ss.hasPermi('map:info:remove')")
    @Log(title = "保障房建筑区域信息数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids) {
        regionInfoService.removeById(ids);
        return AjaxResult.success("删除成功！");
    }
}
